import { ipcMain, shell, BrowserWindow } from 'electron'
import { getSystemIdentifiers } from '../services/systemService'

/**
 * 注册所有IPC处理程序
 */
export function registerIpcHandlers(): void {
  // IPC测试
  ipcMain.on('ping', () => console.log('pong'))

  // 打开浏览器
  ipcMain.on('open-browser', (_, url) => {
    shell.openExternal(url)
  })

  // 获取系统唯一标识符
  ipcMain.handle('get-system-info', async () => {
    return await getSystemIdentifiers()
  })

  // 窗口控制
  ipcMain.on('window-minimize', () => {
    const window = BrowserWindow.getFocusedWindow()
    if (window) window.minimize()
  })

  ipcMain.on('window-maximize', () => {
    const window = BrowserWindow.getFocusedWindow()
    if (window) {
      if (window.isMaximized()) {
        window.unmaximize()
      } else {
        window.maximize()
      }
    }
  })

  ipcMain.on('window-close', () => {
    const window = BrowserWindow.getFocusedWindow()
    if (window) window.close()
  })
}
